package com.masterclient.app.businessmodule.minemodule.collection.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.bean.goods.ProductBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.Utils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * 作者：sean
 * 创建时间：2017/7/24 15:36
 * 功能说明：
 */

public class GoodsCollectAdapter extends BaseQuickAdapter<ProductBean, BaseViewHolder> {

    private int width;

    public GoodsCollectAdapter() {
        super(R.layout.item_footer_good);
        width = (int) ((ScreenUtils.getScreenWidth() - ScreenUtils.dp2px(41)) / 2f);
    }

    @Override
    protected void convert(BaseViewHolder helper, ProductBean item) {

        //渲染价格
        renderAllPrice(helper, item);
        helper.setText(R.id.tv_sub_title, item.getSh_name());

        TextView tvFavoriteNum = helper.getView(R.id.tv_favorite_num);
        tvFavoriteNum.setVisibility(View.GONE);

        ImageView imageView = helper.getView(R.id.iv_goods);
        ViewTransformUtil.glideImageView(mContext, item.getSh_image(), imageView, new RoundedCornersTransformation(0, 0),
                R.mipmap.defaults, width, width);
    }

    private void renderAllPrice(BaseViewHolder helper, ProductBean item) {
        TextView tvPrice = helper.getView(R.id.price);
        TextView tvOfficialPrice = helper.getView(R.id.tv_official_price);

        Utils.set_price_style2(tvPrice, "¥ " + item.getSh_show_price());
        Utils.setDin(tvPrice, mContext);
        tvOfficialPrice.setText("¥" + item.getSh_line_price());
        tvOfficialPrice.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        tvOfficialPrice.setVisibility(View.VISIBLE);
    }
}
